package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.ProductQuestionService;
import com.yunhai.model.entity.dms.DmsProductQuestionEntity;
import com.yunhai.model.vo.dms.DmsProductQuestionQuery;
import com.yunhai.model.vo.dms.DmsProductQuestionVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/productQuestion")
public class ProductQuestionController {

	@Resource
	private ProductQuestionService productQuestionService;


	/**
	 * 获取 ProductQuestion 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getProductQuestionPagination(PaginationVo paginationVo, DmsProductQuestionQuery dmsProductQuestionQuery ) throws Exception {
		IPage page = productQuestionService.getProductQuestionPagination(paginationVo, dmsProductQuestionQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 ProductQuestion 所有数据
	 */
	@GetMapping("/allList")
	public Ret getProductQuestionAllList( DmsProductQuestionQuery dmsProductQuestionQuery ) throws Exception {
		List<DmsProductQuestionEntity> list = productQuestionService.getProductQuestionAllList( dmsProductQuestionQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 ProductQuestion 详情
	 */
	@GetMapping("/{id}")
	public Ret getProductQuestionDetailById(@PathVariable Long id) throws Exception {

	    DmsProductQuestionEntity dmsProductQuestionEntity = productQuestionService.getProductQuestionDetail(id);
		return Ret.ok(dmsProductQuestionEntity);
	}


	/**
	 * 新增 ProductQuestion
	 * */
	@PostMapping("")
	public Ret addProductQuestion(@RequestBody DmsProductQuestionVo dmsProductQuestionVo) throws Exception {

		productQuestionService.addProductQuestion(dmsProductQuestionVo);
		return Ret.ok();
	}


	/**
	 * 更新 ProductQuestion
	 * */
	@PutMapping("")
	public Ret updateProductQuestion(@RequestBody DmsProductQuestionVo dmsProductQuestionVo) throws Exception {

		productQuestionService.updateProductQuestion(dmsProductQuestionVo);
		return Ret.ok();
	}


	/**
	 * 删除 ProductQuestion
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveProductQuestion( @RequestBody List<Long> ids ) throws Exception {

	    productQuestionService.batchRemoveProductQuestion(ids);
		return Ret.ok();
	}
}
